package com.xia.adapter;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.smart_home.R;
import com.xia.bean.CameraBean;

public class CameraAdapter extends BaseAdapter {

	private List<CameraBean> mList;

	private LayoutInflater mInflater;

	public CameraAdapter(Context context, List<CameraBean> list) {
		this.mList = list;
		this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.cameradevice, null);
			holder = new ViewHolder();
			holder.imageView = (ImageView) convertView
					.findViewById(R.id.camera_img);
			holder.cameraName = (TextView) convertView
					.findViewById(R.id.camera_name);
			holder.cameraIp = (TextView) convertView
					.findViewById(R.id.camera_ip);
			convertView.setTag(holder);
		} else
			holder = (ViewHolder) convertView.getTag();
		CameraBean bean = mList.get(position);
		holder.imageView.setImageResource(bean.getmImageID());
		holder.cameraName.setText(bean.getmCameraName());
		holder.cameraIp.setText(bean.getmCameraIp());
		 Log.d("list", bean.getmCameraName());
		return convertView;
	}

}

class ViewHolder {
	public ImageView imageView;
	public TextView cameraName;
	public TextView cameraIp;
}